package com.wind.easycode.controller;

import com.wind.easycode.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/sys")
public class TestController {
    private static final Logger log = LoggerFactory.getLogger(TestController.class.getName());
    /**
     * 所有用户列表
     */
    @GetMapping("/list")

    public String list(String url) {
        showServer();
        System.out.println(url);
        HttpResponse httpResponse = null;
        String strResult ="";
        try {
            httpResponse = HttpUtils.doGet(url, "", "", new HashMap<>(), new HashMap<>());
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                strResult = EntityUtils.toString(httpResponse.getEntity());
                System.out.println("strResult:"+strResult);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return strResult;
    }

    private static void showServer(){
        log.info("SYSINFO StartServer : Version: 1.0.0");
        log.info("SYSINFO copyright by (RC).");
        log.info("SYSINFO Login user          : " + System.getProperty("user.name"));
        log.info("SYSINFO Operation System    : " + System.getProperty("os.name") + "/" + System.getProperty("os.version") + "/" + System.getProperty("os.arch"));
        log.info("SYSINFO Server CPU type     : " + System.getProperty("sun.cpu.isalist"));
        log.info("SYSINFO JRE Vendor          : " + System.getProperty("java.vm.vendor"));
        log.error("SYSINFO JVM Version         : " + System.getProperty("java.vm.version"));
        log.error("SYSINFO Java Home directory : " + System.getProperty("java.home"));
        log.error("SYSINFO Current directory   : " + System.getProperty("user.dir"));

    }
}
